HTTP Requests

HTTP requests can be issued via the built-in http and https modules, as well as higher-level wrapper modules such as the popular requests module. The latter is supported out-of-the-box as a helper in the form of _.requests within a notebook.

Note that HTTP requests complete asynchronously, and the _.async helper is used to convert callback-style async patterns into promises that the notebook can wait on to know when the cell has completed execution.


In [1]:
_.async(function(deferred) {
  _.request('http://www.example.org', function(err, response) {
    console.log('Status Code: %d', response.statusCode);
    console.log('Page Title: %s',
                response.body.match(/\<title\>([^\<]*)\<\/title\>/)[1]);

    deferred.resolve();
  })
});


Status Code: 200
Page Title: Example Domain